package com.jiangyg.mall.product.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.product.vo.SkuInfoVO;
import com.jiangyg.mall.product.vo.SkuSaleAttrValueVO;
import com.jiangyg.mall.product.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：sku信息控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:38:48
 */
@RestController
@RequestMapping("/product/sku")
public class SkuController {

    /**
     * sku信息接口
     */
    private final SkuService skuService;

    @Autowired
    public SkuController(SkuService skuService) {
        this.skuService = skuService;
    }

    /**
     * 功能描述：SKU信息分页查询
     *
     * @param pagination 分页参数
     * @return 返回分页商品属性
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<SkuInfoVO>> select(@RequestBody Pagination<SkuInfoVO> pagination) throws Exception {
        return Result.ok(skuService.selectPagination(pagination));
    }

    /**
     * 功能描述：根据ID获取SKU信息
     *
     * @param request 请求
     * @param skuId   SKUID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<SkuInfoVO> info(HttpServletRequest request, @RequestParam(name = "skuId") Long skuId) throws Exception {
        return Result.ok(skuService.selectById(skuId));
    }

    /**
     * 功能描述：根据ID获取商品信息
     *
     * @param request 请求
     * @param skuId   SKUID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/item")
    public Result<Object> item(HttpServletRequest request, @RequestParam(name = "skuId") Long skuId) throws Exception {
        return Result.ok(skuService.item(skuId));
    }

    /**
     * 功能描述：根据ID获取商品信息
     *
     * @param request 请求
     * @param skuId   SKUID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/sale-attr-list")
    public Result<List<SkuSaleAttrValueVO>> saleAttrList(HttpServletRequest request, @RequestParam(name = "skuId") Long skuId) throws Exception {
        return Result.ok(skuService.saleAttrList(skuId));
    }

    /**
     * 功能描述：根据ID集合获取商品列表信息
     *
     * @param request 请求
     * @param skuIds  skuIds
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/list")
    public Result<List<SkuInfoVO>> list(HttpServletRequest request, @RequestBody List<Long> skuIds) throws Exception {
        return Result.ok(skuService.selectListByIds(skuIds));
    }

}
